package com.alinesno.cloud.base.boot.repository;

import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.alinesno.cloud.base.boot.entity.ManagerAccountEntity;
import com.alinesno.cloud.common.facade.orm.repository.IBaseJpaRepository;

/**
 * <p>
  *  持久层接口
 * </p>
 *
 * @author WeiXiaoJin
 * @since 2018-12-16 17:53:19
 */
public interface ManagerAccountRepository extends IBaseJpaRepository<ManagerAccountEntity, String> {

	ManagerAccountEntity findByLoginName(String loginName);

	/**
	 * 更新用户密码
	 * @param newPassword
	 * @param userId
	 */
	@Modifying
	@Transactional
	@Query("UPDATE ManagerAccountEntity e SET e.password = ?1 WHERE e.id = ?2")
	void updateManagerAccountPassword(String newPassword, String userId);

	@Modifying
	@Transactional
	@Query("UPDATE ManagerAccountEntity e SET e.password = ?1 WHERE e.id = ?2")
	void updateAvator(String path, String id);

	ManagerAccountEntity findByPhone(String phone);

	ManagerAccountEntity findByEmail(String email);
	
	@Query("SELECT t2 FROM ManagerAccountRoleEntity t1  LEFT JOIN ManagerAccountEntity t2 on t1.accountId = t2.id where t1.roleId=?1 and t2.id IS NOT NULL")
	Page<ManagerAccountEntity> findRoleMemberByPage(String roleId , Pageable pageable);

}
